from django.shortcuts import render
from search.models import *
from userauth.views import *
from userauth.models import *
from django.shortcuts import HttpResponse, render, redirect
from django.contrib.auth.decorators import login_required

def getrealname(user):
    return UserInformation.objects.get(uid = user).realname

# Create your views here.
class Search:
    def Mainpage(request):
        if request.user.id == None:
            return redirect("/user/login")
        selected = Selected.objects.filter(uid = request.user.id)
        content_list1 = []
        for user in selected:
            content_list1.append(user.content)
        matches = Match.objects.filter(uid = request.user.id)
        content_list2 = []
        users_select = []
        for pairs in matches:
            dat = []
            others = Selected.objects.filter(uid = pairs.matchid)
            for res in others:
                dat.append(res.content)
            content_list2.append([getrealname(pairs.matchid),dat])
        #print(content_list2)
        return render(request, 'search_main.html',{"list1":content_list1, "list2":content_list2})
